from rest_framework import serializers

from apps.goods.models import SPU, SPUSpecification, Brand, GoodsCategory


class SpuModel(serializers.ModelSerializer):

    class Meta:
        model=SPU
        fields=['id','name']

class SPUViewSetModel(serializers.ModelSerializer):
    """
                "id": "商品SPU ID",
                "name": "SPU名称",
                "brand": "品牌名称",
                "brand_id": "品牌id",
                "category1_id": "一级分类id",
                "category2_id": "二级分类id",
                "category3_id": "三级分类id",
                "sales": "SPU商品销量",
                "comments": "SPU商品评论量",
                "desc_detail": "商品详情",
                "desc_pack": "商品包装",
                "desc_service": "售后服务"
    """
    brand=serializers.StringRelatedField(read_only=True)
    brand_id=serializers.IntegerField()
    category1_id=serializers.IntegerField()
    category2_id=serializers.IntegerField()
    category3_id=serializers.IntegerField()


    class Meta:
        model=SPU
        fields="__all__"
        read_only_fields = ('category1', 'category2', 'category3')


class BrandSimpleSer(serializers.ModelSerializer):
    class Meta:
        model=Brand
        fields='__all__'

class CategoriesSer(serializers.ModelSerializer):
    class Meta:
        model=GoodsCategory
        fields=['id','name']